package gdconf

import (
	"server_cluster/common/logger"
)

// 装备配置表

type EquipConfig struct {
	Id               int32         `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 装备id
	Group            int32         `csv:"Group,omitempty"`                           // 装备组
	WeaponPos        int32         `csv:"WeaponModel,omitempty"`                     // 装备位置
	WeaponPromote    int32         `csv:"WeaponStage,omitempty"`                     // 装备阶段
	WeaponPower      int32         `csv:"WeaponPower,omitempty"`                     // 装等
	JewelNum         int32         `csv:"JewelNum,omitempty"`                        // 宝石数量
	MaxSkill2        int16         `csv:"MaxSkill2,omitempty"`                       // 技能数量上限
	LevelGroupWeight IntArrayArray `csv:"IntensifyGroup,omitempty"`                  // 升级组与权重
	BaseConvExp      int32         `csv:"Exp,omitempty"`                             // 基础转化经验
	ExSkill          IntArray      `csv:"ExclusiveSkills,omitempty"`                 // 专属技能
	SkillGroup       int32         `csv:"OrdinarySkillsGroup,omitempty"`             // 技能组
}

func (e *EquipConfig) TableName() string {
	return "config_equip"
}

func (g *GameDataConfig) saveEquipConfig() {
	saveTableToDb[EquipConfig](g.Db, readTable[EquipConfig](g.CsvPathPrefix+"equipment.csv"))
}

func (g *GameDataConfig) loadEquipConfig() {
	g.GameDataMaps.EquipConfigMap = make(map[int32]*EquipConfig)
	for _, equipConfig := range loadTableFromDb[EquipConfig](g.Db) {
		g.GameDataMaps.EquipConfigMap[equipConfig.Id] = equipConfig
	}
	logger.Info("EquipConfig Count: %v", len(g.GameDataMaps.EquipConfigMap))
}

func GetEquipConfig(id int32) *EquipConfig {
	value, exist := CONF.GameDataMaps.EquipConfigMap[id]
	if !exist {
		logger.Error("[ConfigNotFound] EquipConfig, id: %v", id)
		return nil
	}
	return value
}

func GetEquipConfigMap() map[int32]*EquipConfig {
	return CONF.GameDataMaps.EquipConfigMap
}
